class Car:
    '''A simple attempt to simulate a car'''

    def __init__(self,make,model,year):
        '''Initialize the attributes that describe the car'''
        self.make=make
        self.model=model
        self.year=year
        self.odometer_reading=0

    def get_descriptive_name(self):
        '''Return neat descriptive informaiton'''
        long_name=f"{self.year} {self.make} {self.model}"
        return long_name.title()

    def read_odometer(self):
        '''Print a message indicating car mileage'''
        print(f"This car has {self.odometer_reading} miles on it .")

    #使用方法修改属性
    def update_odometer(self,mileage):
        '''
        Set the odometer reading to the specified value
        Do not reverse the odometer reading
        '''
        if mileage>=self.odometer_reading:
           self.odometer_reading=mileage
        else:#此处是禁止将里程表读数往回调
            print("You can't roll back an odometer !")
    
    #通过方法对属性的值进行递增
    def increment_odometer(self,miles):
        '''Increase the odometer reading by a specified amount
           Suppress negative increments
        '''
        if miles>=0:
           self.odometer_reading+=miles
        else:
            print("Error increase !")


my_new_car=Car('audi','a4',2009)
print(my_new_car.get_descriptive_name())
my_new_car.read_odometer()

#直接修改属性的值
my_new_car.odometer_reading=23
my_new_car.read_odometer()

#通过方法修改属性的值
my_new_car.update_odometer(23)
my_new_car.read_odometer()

#通过方法对属性的值进行增值
my_used_car=Car('subaru','outback',2015)
print(my_used_car.get_descriptive_name())

my_used_car.update_odometer(23_500)
my_used_car.read_odometer()

my_used_car.increment_odometer(100)
my_used_car.read_odometer()

